package com.example.weather.controller;

import com.example.weather.dto.WeatherResponse;
import com.example.weather.service.GetWeatherDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class GetWeatherDataController {
    @Autowired
    GetWeatherDataService getWeatherDataService;

/**
 * 应用接口： 一. http://localhost:8001/weather/search?cityid=110170  get请求
 */
    @RequestMapping("/search")
    @ResponseBody  //天气查询数据的json格式字符串
    public WeatherResponse search(String cityid){

        // restTemplate.getForObject("","");
        // https://apis.tianapi.com/tianqi/index
        // https://apis.tianapi.com/tianqi/index?key=你的APIKEY&city=101020100&type=1
        // key:58147479384231dc837ee5fd1288e6f2

        WeatherResponse weatherResponse = getWeatherDataService.searchWeather(cityid);
        return weatherResponse;
    }
}
